package cl.scene.badseeds;

import com.mongodb.DB;
import com.mongodb.Mongo;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;

import java.io.*;
import java.net.UnknownHostException;

/**
 * Created by IntelliJ IDEA.
 * User: Patricio
 * Date: 24-11-2010
 * Time: 10:09:15 PM
 */
public class Main {
    public static void main(String argv[]) throws FileNotFoundException, UnknownHostException {


//        System.setProperty("org.eclipse.jetty.util.UrlEncoding.charset", "UTF-8");
        Mongo dbcon = new Mongo("127.0.0.1", 27017);
        DB database = dbcon.getDB("badseeds");


        Server server = new Server(8080);
//        server.setAttribute("org.eclipse.jetty.server.Request.queryEncoding", "UTF-8");
        try {
            ContextHandler context = new ContextHandler();
            AnnounceHandler announceHandler = new AnnounceHandler();
            announceHandler.setDatabase(database);
            context.setContextPath("/a");
            context.setResourceBase(".");
            context.setClassLoader(Thread.currentThread().getContextClassLoader());
            context.setHandler(announceHandler);
            server.setHandler(context);
            server.start();
            server.join();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
